'(c) 2010 - Oliver Hine - www.oliverhine.com

Imports System.Web.Script.Serialization
Imports DotNetNuke
Imports DotNetNuke.Common
Imports DotNetNuke.UI.Utilities
Imports DotNetNuke.Security.Permissions

Namespace DotNetNuke.Modules.Html

    Public Class HtmlModuleBase
        Inherits Entities.Modules.PortalModuleBase

        Private _replaceTokens As Boolean = False
        Private _jQueryUI As Boolean = False
        Private _displayMode As String = "tabs"
        Private _displayStyle As String = String.Empty
        Private _cacheKey As String = "h{0}" ':{1}"
        Private _defaultControl As String = "HtmlModule.ascx"

        Private _pendingUpdate As Boolean = False

        Public ReadOnly Property GroupUID() As Guid
            Get
                If Request.QueryString("guid") IsNot Nothing Then
                    Try
                        Return New Guid(Request.QueryString("guid"))
                    Catch ex As Exception
                        'bad userspecified guid, so lets just ignore this error and continue like it didn't occur
                        Return Null.NullGuid
                    End Try
                Else
                    If Request.QueryString("title") IsNot Nothing Then
                        Return DataProvider.Instance().GetHtmlExists(Me.ModuleId, Request.QueryString("title").ToString())
                    Else
                        Return Null.NullGuid
                    End If
                End If
            End Get
        End Property

        Public ReadOnly Property UniqueKey() As String
            Get
                If Null.IsNull(Me.GroupUID) Then
                    Return Me.ModuleId.ToString()
                Else
                    Return Me.GroupUID.ToString().Replace("-", "")
                End If
            End Get
        End Property

        Public ReadOnly Property PendingUpdate() As Boolean
            Get
                Return _pendingUpdate
            End Get
        End Property

        Public ReadOnly Property HtmlContentCacheKey() As String
            Get
                Return String.Format(_cacheKey, Me.UniqueKey, PortalSettings.UserMode)
            End Get
        End Property

        Public Property ReplaceTokens() As Boolean
            Get
                If CType(Settings("HtmlText_ReplaceTokens"), String) <> "" Then
                    _replaceTokens = CType(Settings("HtmlText_ReplaceTokens"), Boolean)
                End If

                Return _replaceTokens
            End Get
            Set(ByVal value As Boolean)
                _pendingUpdate = True
                _replaceTokens = value
            End Set
        End Property
        Public Property jQueryUI() As Boolean
            Get
                If CType(Settings("HtmlText_jQueryUI"), String) <> "" Then
                    _jQueryUI = CType(Settings("HtmlText_jQueryUI"), Boolean)
                End If
                Return _jQueryUI
            End Get
            Set(ByVal value As Boolean)
                _pendingUpdate = True
                _jQueryUI = value
            End Set
        End Property
        Public Property DisplayMode() As String
            Get
                If CType(Settings("HtmlText_DisplayMode"), String) <> "" Then
                    _displayMode = Settings("HtmlText_DisplayMode").ToString
                End If

                Return _displayMode
            End Get
            Set(ByVal value As String)
                _pendingUpdate = True
                _displayMode = value
            End Set
        End Property
        Public Property DisplayStyle() As String
            Get
                If CType(Settings("HtmlText_DisplayStyle"), String) <> "" Then
                    _displayStyle = Settings("HtmlText_DisplayStyle").ToString
                End If

                Return _displayStyle
            End Get
            Set(ByVal value As String)
                _pendingUpdate = True
                _displayStyle = value
            End Set
        End Property
        Public Property DefaultControl() As String
            Get
                Return _defaultControl
            End Get
            Set(ByVal value As String)
                _pendingUpdate = True
                Select Case value
                    Case "0" 'html module
                        _defaultControl = "HtmlModule.ascx"
                    Case "2" 'manage workflow module
                        _defaultControl = "ManageWorkflow.ascx"
                    Case Else
                        _defaultControl = "HtmlModule.ascx"
                End Select

            End Set
        End Property

        Public Sub SaveSettings()
            If Me.PendingUpdate = True Then

            End If
        End Sub

    End Class

End Namespace